package org.tacademy.and12.jyh.menutest;

import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
	final static int MENU_FIRST = Menu.FIRST + 1;
	final static int MENU_SECOND = Menu.FIRST + 2;

	TextView textview;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		textview = (TextView) findViewById(R.id.textview1);
		
		registerForContextMenu(textview);
		
		
	}
	
	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		// TODO Auto-generated method stub
		if ( v == textview) {
			menu.add(0, MENU_FIRST, 1, "MenuOne");//.setIcon(R.drawable.ic_launcher).setShortcut(numericChar, alphaChar);
			menu.add(0, MENU_SECOND, 2, "MenuTwo"); 
		}
		//super.onCreateContextMenu(menu, v, menuInfo);
	}
	@Override
	public View onCreatePanelView(int featureId) {
		// TODO Auto-generated method stub
		if (featureId == Window.FEATURE_OPTIONS_PANEL){
			TextView tv = new TextView(this);
			tv.setText("menu custom text:");
			tv.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
				//	closeContextMenu();
					Toast.makeText(MainActivity.this, "www", Toast.LENGTH_SHORT).show();
				}
			});
			return tv;
		}
		return super.onCreatePanelView(featureId);
	}
	@Override
	public boolean onContextItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case MENU_FIRST:
			
			break;

		case MENU_SECOND:
			break;
		}
		return true;//super.onContextItemSelected(item);
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case R.id.menuOne:
			Toast.makeText(this, "MenuOneSelected", Toast.LENGTH_SHORT).show();
			break;
		case R.id.menuTwo:
			Toast.makeText(this, "MenuTwoSelected", Toast.LENGTH_SHORT).show();
			break;
		case R.id.itemThree:
			Toast.makeText(this, "MenuThreeSelected", Toast.LENGTH_SHORT).show();
			break;
		}
		return true;
	}

}
